/*
 *    Copyright (c) 2018-2025, daoism All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: daoism
 */

package com.mkh.st.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mkh.st.admin.api.dto.CompanyPageDTO;
import com.mkh.st.admin.api.dto.CompanySaveDTO;
import com.mkh.st.admin.api.vo.CompanyDetailVO;
import com.mkh.st.admin.api.vo.CompanyPageVO;
import com.mkh.st.admin.api.vo.SelectCompanyVO;
import com.mkh.st.admin.service.SysCompanyInfoService;
import com.mkh.st.common.core.util.R;
import com.mkh.st.common.log.annotation.SysLog;
import com.mkh.st.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;


/**
 * 公司信息表
 *
 * @author daoism code generator
 * @date 2021-07-06 09:36:04
 */
@RestController
@AllArgsConstructor
@RequestMapping("/syscompanyinfo" )
@Api(value = "syscompanyinfo", tags = "公司信息表管理")
public class SysCompanyInfoController {

    private final SysCompanyInfoService sysCompanyInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param dto 公司信息
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R<IPage<CompanyPageVO>> getSysCompanyInfoPage(Page page, CompanyPageDTO dto) {
		dto.setTenantId(SecurityUtils.getUser().getTenantId());
        return R.ok(sysCompanyInfoService.getSysCompanyInfoPage(page,dto));
    }


    /**
     * 通过id查询公司信息表
     * @param companyId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{companyId}" )
    public R<CompanyDetailVO> getCompanyDetail(@PathVariable("companyId" ) Long companyId) {
        return R.ok(sysCompanyInfoService.getCompanyDetail(companyId));
    }

    /**
     * 新增公司信息表
     * @param dto 公司信息表
     * @return R
     */
    @ApiOperation(value = "保存公司信息", notes = "保存公司信息")
    @SysLog("保存公司信息" )
    @PostMapping("/saveCompanyInfo")
    public R saveCompanyInfo(@Valid @RequestBody CompanySaveDTO dto) {
        return R.ok(sysCompanyInfoService.saveCompanyInfo(dto));
    }


	@ApiOperation(value = "选择公司", notes = "选择公司")
	@GetMapping("/getSysCompanyInfoList" )
	public R<List<SelectCompanyVO>> getSysCompanyInfoList(CompanyPageDTO dto) {
		dto.setTenantId(SecurityUtils.getUser().getTenantId());
		return R.ok(sysCompanyInfoService.getSysCompanyInfoList(dto));
	}

	@ApiOperation(value = "公司列表", notes = "公司列表")
	@GetMapping("/companyInfoList")
	public R<List<SelectCompanyVO>> companyInfoList( @ApiParam(name = "menuCode", value = "菜单code",required = true) String menuCode) {
		return R.ok(sysCompanyInfoService.companyInfoList(menuCode));
	}

}
